<html>

	<head>
		<title></title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="renderer" content="webkit">
		<title>站细管理系统</title>
		<link rel="stylesheet" type="text/css" href="/layuicms/layui/css/layui.css" />
		<!--<link rel="stylesheet" type="text/css" href="css/style2.css" />-->
		<link rel="stylesheet" type="text/css" href="/admin/css/style.css" />
		<link rel="stylesheet" href="/layuicms/layui_ext/dtree/dtree.css" media="all" />
		<link rel="stylesheet" href="/layuicms/layui_ext/dtree/font/dtreefont.css" media="all" />
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/ueditor.all.js"></script>
		<script type="text/javascript" charset="utf-8" src="/admin/ueditor/lang/zh-cn/zh-cn.js"></script>
		<script type="text/javascript" src="/layuicms/layui_ext/dist/dtree.js"></script>
		<style type="text/css">
			.boxs {
				height: 100vh;
				overflow: hidden;
			}

			#edui1_iframeholder {
				overflow: hidden;
			}
			div #layui-layer2 .layui-layer layui-layer-page{
				z-index: 198910161; !important;
			}
		</style>
	</head>

	<body style="overflow: hidden;position: relative;">
		<div class="boxs">
			<div class="contentBox">
				<div class="contentLeft">
					<!--<blockquote class="layui-elem-quote">
						<a href="javascript:void(0)" id="removeOrg" onclick="closeToEditByZdid()"><i class="icon-x"></i></a>
					</blockquote>-->
					<div class="tree-list" style="overflow: auto;" id="toolbarDiv">
						<span id="1" style="/* display: none; */"><b>文件编号</b></span><br>
						<span id="2" style="/* display: none; */"><b>文件标题</b></span><br>
						<span id="3" style="/* display: none; */"><b>站名</b></span><br>
						<span id="4" style="/* display: none; */"><b>公司名称</b></span><br>
						<span id="5" style="/* display: none; */"><b>日期</b></span><br>
						<ul id="articleTree" class="dtree" data-id="0" style="height: auto;"></ul>
					</div>
				</div>
				<form action="" method="post" class="layui-form" id="dataFrm" lay-filter="dataFrm">
				<div class="contentRight layui-row">
					<div class="layui-col-md6 oldContext">
						<div class="old-box">
							<div class="old-title">
								<button type="button" class="close" aria-label="Close">
									<span aria-hidden="true">×</span>
								</button>
								<button type="button" class="oldCompare">旧版</button>
								<button type="button" class="bgCompare">参考编规</button>
							</div>
							<div id="oldContext">
							</div>
						</div>
					</div>
					<div class="layui-col-md6 newContext" id="newContext" style="width: 50%;!important;">
						<div class="new-box" style="">
							<div class="new-title">
								<span>新版</span>
							</div>
						<!--	<div class="imgTips">
								<span>图片支持png, jpg, jpeg, gif, bmp</span>
							</div>-->
							<div>
								<textarea name="articleContext" id="editor"  style="width:100%;height:auto;"></textarea>
							</div>
							<div class="e-action">
								<div id="dfzd">
									<button type="button" lay-submit="" class="layui-btn layui-btn-normal layui-btn-sm save-btn" id="doSubmit">保存修改</button>
								</div>
							</div>
						</div>
					</div>
				</div>
				</form>
			</div>
		</div>
		<div id="groupBoxEdit">
			<p>请选择要编辑的车站:</p>
			<div id="organizationContentEdit">
				<span class="organizationBtn organizationBtnIdEdit2">平塘站<input type="hidden" value="2"></span>
				<span class="organizationBtn organizationBtnIdEdit3">良江站<input type="hidden" value="3"></span>
				<span class="organizationBtn organizationBtnIdEdit4">来宾站<input type="hidden" value="4"></span>
				<span class="organizationBtn organizationBtnIdEdit5">凤凰站<input type="hidden" value="5"></span>
				<span class="organizationBtn organizationBtnIdEdit8">白山站<input type="hidden" value="8"></span>
				<span class="organizationBtn organizationBtnIdEdit9">进德站<input type="hidden" value="9"></span>
				<span class="organizationBtn organizationBtnIdEdit10">古瓦站<input type="hidden" value="10"></span>
				<span class="organizationBtn organizationBtnIdEdit11">白鹤隘站<input type="hidden" value="11"></span>
				<span class="organizationBtn organizationBtnIdEdit12">合山站<input type="hidden" value="12"></span>
				<span class="organizationBtn organizationBtnIdEdit13">黎塘站<input type="hidden" value="13"></span>
				<span class="organizationBtn organizationBtnIdEdit14">稔竹站<input type="hidden" value="14"></span>
				<span class="organizationBtn organizationBtnIdEdit15">沙江站<input type="hidden" value="15"></span>
				<span class="organizationBtn organizationBtnIdEdit16">六景站<input type="hidden" value="16"></span>
				<span class="organizationBtn organizationBtnIdEdit17">伶俐站<input type="hidden" value="17"></span>
				<span class="organizationBtn organizationBtnIdEdit18">邕宁站<input type="hidden" value="18"></span>
				<span class="organizationBtn organizationBtnIdEdit19">屯里站<input type="hidden" value="19"></span>
				<span class="organizationBtn organizationBtnIdEdit20">南宁南站<input type="hidden" value="20"></span>
				<span class="organizationBtn organizationBtnIdEdit21">沙井站<input type="hidden" value="21"></span>
				<span class="organizationBtn organizationBtnIdEdit22">南化站<input type="hidden" value="22"></span>
				<span class="organizationBtn organizationBtnIdEdit23">金鸡村站<input type="hidden" value="23"></span>
				<span class="organizationBtn organizationBtnIdEdit24">江西村站<input type="hidden" value="24"></span>
				<span class="organizationBtn organizationBtnIdEdit25">维罗站<input type="hidden" value="25"></span>
				<span class="organizationBtn organizationBtnIdEdit26">扶绥站<input type="hidden" value="26"></span>
				<span class="organizationBtn organizationBtnIdEdit27">渠黎站<input type="hidden" value="27"></span>
				<span class="organizationBtn organizationBtnIdEdit28">渠旧站<input type="hidden" value="28"></span>
				<span class="organizationBtn organizationBtnIdEdit29">濑湍站<input type="hidden" value="29"></span>
				<span class="organizationBtn organizationBtnIdEdit30">崇左站<input type="hidden" value="30"></span>
				<span class="organizationBtn organizationBtnIdEdit31">天西站<input type="hidden" value="31"></span>
				<span class="organizationBtn organizationBtnIdEdit32">亭亮站<input type="hidden" value="32"></span>
				<span class="organizationBtn organizationBtnIdEdit33">龙伯屯站<input type="hidden" value="33"></span>
				<span class="organizationBtn organizationBtnIdEdit34">宁明站<input type="hidden" value="34"></span>
				<span class="organizationBtn organizationBtnIdEdit35">夏石站<input type="hidden" value="35"></span>
				<span class="organizationBtn organizationBtnIdEdit36">凭祥北<input type="hidden" value="36"></span>
				<span class="organizationBtn organizationBtnIdEdit37">凭祥站<input type="hidden" value="37"></span>
				<span class="organizationBtn organizationBtnIdEdit41">小平阳站<input type="hidden" value="41"></span>
				<span class="organizationBtn organizationBtnIdEdit42">demo<input type="hidden" value="42"></span>
				<span class="organizationBtn organizationBtnIdEdit47">沧州站<input type="hidden" value="47"></span>
				<span class="organizationBtn organizationBtnIdEdit48">龙伯屯东站<input type="hidden" value="48"></span>
				<span class="organizationBtn organizationBtnIdEdit49">任丘站<input type="hidden" value="49"></span>
				<span class="organizationBtn organizationBtnIdEdit50">河间站<input type="hidden" value="50"></span>
				<span class="organizationBtn organizationBtnIdEdit51">东光站<input type="hidden" value="51"></span>
			</div>
			<div id="groupContentEdit">
				<span class="groupBtn">全站<input type="hidden" value="2"></span>
				<span class="groupBtn">来宾车间<input type="hidden" value="4"></span>
				<span class="groupBtn">黎塘<input type="hidden" value="6"></span>
				<span class="groupBtn">六景车间<input type="hidden" value="7"></span>
				<span class="groupBtn">南宁南站<input type="hidden" value="8"></span>
				<span class="groupBtn">崇左车间<input type="hidden" value="9"></span>
				<span class="groupBtn">凭祥车间<input type="hidden" value="10"></span>
			</div>
			<span class="closeGroupBoxEdit" style="">确定</span>
		</div>
		<script type="text/javascript" src="/layuicms/layui/layui.js"></script>
		<script type="text/javascript" src="/layuicms/layui_ext/dist/dtree.js"></script>
		<script type="text/javascript">
            layui.extend({
                dtree: '/layuicms/layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
            }).use(['jquery','layer','dtree','layedit'], function() {
                var $ =  layui.jquery;
                var layer = layui.layer;
                var dtree = layui.dtree;
                var layedit = layui.layedit;
                var h=$(document).height()-200;
                var articleTree;
                //创建一个编辑器  初始化富文本
                var editIndex = layedit.build('remark');
                //初始化富文本
                var ue = UE.getEditor('editor', {
                    initialFrameWidth: '100%',
                    initialFrameHeight: 680,
                    retainOnlyLabelPasted: false,
                    elementPathEnabled : false,
                    wordCount:false,
                	pasteplain: false,
                    toolbars: [
                        [
                            'source', //源代码
                            'undo', //撤销
                            'redo', //重做
                            'bold', //加粗
                            'preview', //预览
                            'horizontal', //分隔线
                            'removeformat', //清除格式
                            'simpleupload', //单图上传
                            'insertimage', //多图上传
                            'inserttable', //插入表格
                            'edittable', //表格属性
                            'emotion', //表情
                            'justifyleft', //居左对齐
                            'justifyright', //居右对齐
                            'justifycenter', //居中对齐
                            'justifyjustify', //两端对齐
                            'forecolor', //字体颜色
                            'fullscreen', //全屏
                            'attachment', //附件
                        ]
                    ],
                    autoHeightEnabled: true,
                    autoFloatEnabled: true,
                    zIndex: 19891015
                });

                ue.ready(function() {
                    ue.setHeight(h);
                });
                // 初始化树
                articleTree = dtree.render({
                    elem: "#articleTree",
                    dataStyle: "layuiStyle",
                    dataFormat: "list",  //配置data的风格为list
                    response: {message: "msg", statusCode: 0},
                    initLevel: "1",
                    icon: "2",
                    toolbar: true,
                    record: true,
                    line: true,
                    scroll:"#toolbarDiv",
                    url: '/article/loadArticleManagerLeftJson', // 使用url加载（可与data加载同时存在）
                    toolbarFun: {
                        loadToolbarBefore: function (buttons, param, $div) {
                            if (param.context=="正文") { // 如果是叶子节点
                                buttons.delToolbar = "";
                                buttons.addToolbar = "";
                                buttons.editToolbar = "";// 取消新增功能
                            }
                        //    UE.getEditor('editor').destroy();
                            return buttons; // 将按钮对象返回
                        },
                        addTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/article/addArticle",
                                success: function (result) {
                                    //articleTree.changeTreeNodeAdd(treeNode.nodeId); // 添加成功，返回ID
                                    articleTree.changeTreeNodeAdd(true); // 添加成功
                                    //articleTree.changeTreeNodeAdd(result.data); // 添加成功，返回一个JSON对象
                                    articleTree.changeTreeNodeAdd("refresh"); // 添加成功，局部刷新树
                                },
                                error: function () {
                                    articleTree.changeTreeNodeAdd(false); // 添加失败
                                }
                            });
                        },
                        editTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/article/updateArticle",
                                success: function (result) {
                                    articleTree.changeTreeNodeEdit(true);// 修改成功
                                    //DTree1.changeTreeNodeEdit(result.param); // 修改成功，返回一个JSON对象
                                },
                                error: function () {
                                    //DTree1.changeTreeNodeEdit(false);//修改失败
                                }
                            });
                        },
                        delTreeNode: function (treeNode, $div) {
                            var jsonData = JSON.stringify(treeNode);
                            $.ajax({
                                type: "post",
                                data: {data: jsonData},
                                url: "/article/deleteArticle",
                                success: function (result) {
                                    articleTree.changeTreeNodeDel(true); // 删除成功
                                },
                                error: function () {
                                    //DTree1.changeTreeNodeDel(false);// 删除失败
                                }
                            });
                        }
                    }
                });
                // 绑定节点点击
				var url = "";
				var id = "";
                dtree.on("node('articleTree')" ,function(obj){
                    id = obj.param.nodeId;
                    $("#nodeId").val(obj.param.nodeId);
                    $("#parentId").val(obj.param.parentId);
                    $.get("/standFile/findStandFileById1/" + id, function (res) {
                        $("#oldContext").html(res.data.item.remark);
                    })
                    $.ajax({
                        type: "post",
                        data: {nodeId: obj.param.nodeId},
                        url: "/article/findArticleTree",
                        success: function (result) {
                            var ue = UE.getEditor('editor');
                            var proinfo=result.data.item.articleContext;
							url="/article/updateArticleById/"+obj.param.nodeId;
							id = obj.param.nodeId;
							if(null!=proinfo){
                                ue.ready(function() {//编辑器初始化完成再赋值
                                    ue.setContent(proinfo);  //赋值给UEditor
                                });
							}else {
                                ue.ready(function() {//编辑器初始化完成再赋值
                                    ue.setContent("");  //赋值给UEditor
                                });
							}
                        }
                    });
                });
                $("#doSubmit").click(function () {
                    //同步富文本和textarea里面的内容
                    layedit.sync(editIndex)
                    var data = $("#dataFrm").serialize();
                    $.post(url,data,function (res) {
                        if(res.code==20000){
                            /*tableIns.reload();*/
                        }
                        layer.msg(res.message);
                     //   layer.close(mainIndex);
                    })
                });
                $(function(){
                    /*点击选择车站 显示编辑车站层*/
                    $("#showE-action").on("click",function(){
                        $("#groupBoxEdit").toggle();
                    });
                    $("#organizationContentEdit span,#organizationContent span,#groupContentEdit .groupBtn,#groupContent .groupBtn").on("click",function(){
                        $(this).toggleClass("fontColor");
                    });
                    /*选择编辑的车站*/
                    $("#organizationContentEdit span").each(function (index, domEle) {
                        $(domEle).on("click",function(){
                            var i=$(this);
                            if(i.hasClass("fontColor")){
                                var vals=$(i).find("input").val();
                                var txt=$(i).text();
                                //alert(txt);
                                $("#showOrganization").append('<a href="#" class="organizationBtn organizationBtnIdEdit'+vals+'" onclick="toEditByZdid()">'+txt+'<input type="hidden" value="+"vals"+"></a>');
                            }else{
                                var vals=$(i).find("input").val();
                                $("#showOrganization").find(".organizationBtnIdEdit"+vals+"").remove();
                            }
                        });
                    });
                    /*快速选择车间里的车站*/
                    $("#groupContentEdit .groupBtn").eq(0).click(function(){
                        if($(this).hasClass("fontColor")){
                            $("#organizationContentEdit .organizationBtn").addClass("fontColor");
                            $("#organizationContentEdit span").each(function (index, domEle) {
                                var vals=$(domEle).find("input").val();
                                var txt=$(domEle).text();
                                var span1='<a href="#" class="organizationBtn organizationBtnIdEdit'+vals+'" onclick="toEditByZdid()">'+txt+'<input type="hidden" value="+"vals"+"></a>';
                                $("#showOrganization").append(span1);
                            });

                        }else{
                            $("#organizationContentEdit .organizationBtn").removeClass("fontColor");
                            $("#showOrganization .organizationBtn").remove();
                        }

                    });

                    /*同步到车次*/
                    $("#organizationContent span").each(function (index, domEle) {
                        $(domEle).on("click",function(){
                            var i=$(this);
                            if(i.hasClass("fontColor")){
                                var vals=$(i).find("input").val();
                                var txt=$(i).text();
                                //alert(txt);
                                $("#showGroupBox").append('<a href="#" class="organizationBtn organizationBtnId'+vals+'">'+txt+'<input type="hidden" value="+"vals"+"></a>');
                            }else{
                                var vals=$(i).find("input").val();
                                $("#showGroupBox").find(".organizationBtnId"+vals+"").remove();
                            }
                        });
                    });
                    /*关闭编辑车站层*/
                    $(".closeGroupBoxEdit").click(function(){
                        $("#groupBoxEdit").hide();
                    });
                })
            });
		</script>
	</body>
</html>